from celery import Celery
from celery.app.control import Inspect
from celery.result import AsyncResult
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

# 创建 Celery 应用程序
celery = Celery(
    'tasks',
    broker='redis://127.0.0.1:6379/5',  # Redis 连接信息
    # backend='redis://127.0.0.1:6379/5',  # Redis 连接信息 - 存储celery每个任务的执行结果
    # timezone='Asia/Shanghai',  # 设置时区为 "Asia/Shanghai"
    broker_connection_retry_on_startup=True,
    include=['celery_tasks.wjx_celery_tasks']
)

# 创建数据库连接引擎
engine = create_engine(
    "mysql+pymysql://root:Yydj_2023f@rm-2vc17il54x88franjho.mysql.cn-chengdu.rds.aliyuncs.com:3306/analysis_test",
    pool_size=10,  # 设置连接池大小
    max_overflow=1000,  # 设置允许的最大连接数
)

# 创建数据库会话工厂
DBSession = sessionmaker(bind=engine)
